package Practice2;

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.IOException;
import java.io.PrintWriter;

public class ResponseIOServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        System.out.println(response.getCharacterEncoding()); // 默认ISO-8859-1
        response.setCharacterEncoding("UTF-8");
        // 通过响应头设置浏览器也使用UTF-8：
        response.setHeader("Content-Type","text/html; charset=UTF-8");
        // 也可以用以下代码：（推荐）
        // 此方法一定要在获取流对象之前调用才有效
//        response.setContentType("text/html; charset=UTF-8");
        PrintWriter writer = response.getWriter();
//        response.getOutputStream(); 两者只能获取其一。
        writer.write("response's content!");
        writer.write("waibibabo歪比巴卜");
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }
}
